package com.huang.consumer_mall.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huang.consumer_mall.dao.BaseDao;
import com.huang.consumer_mall.model.PageCondition;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class BaseService<D extends BaseDao<T>,T> {
    @Autowired
    protected D dao;

    public void insert(T t){dao.insert(t);}

    public void update(T t){dao.update(t);}

    public List<T>  findList(T t) {
         return dao.findList(t);
    }

    public T find (T t){
        return dao.find(t);
    }

    public void deleteById (T t){dao.deleteById(t);}

    public PageInfo<T> page(PageCondition<T> condition){
        return PageHelper.startPage(condition.getPageNum(),condition.getPageSize())
                .doSelectPageInfo(()->dao.findList(condition.getCondition()));
    }
}
